<template>
  <div>
    <el-dialog width="70%" :visible.sync="formShow" @close="handleClickDeal('cancel')" v-dialog-drag  :modal-append-to-body="false" :close-on-click-modal="false">
      <span slot="title">
        <i class="iconfont icon-rizhi"></i>
        <span>{{title}}</span>
      </span>

      <div class="WholeScroll" style="max-height: 65vh;overflow-y: auto;overflow-x: hidden"
           v-loading="isLoading"
           element-loading-text="电子日志生成中，请稍后..."
           element-loading-spinner="el-icon-loading"
           element-loading-background="rgba(0, 0, 0, 0.8)">
        <el-form :model="formBaseData" ref="formBaseData" :rules="formBaseRules" class="measurepaycompensation_detail_form">

          <el-row>
            <el-col :span="12">
              <el-form-item label="公司" prop="companyId" :label-width="formlabelWidth">
                <el-select
                  style="margin: 0; margin-right: 15px;width: 100%"
                  class="select"
                  size="small"
                  v-model="formBaseData.companyId"
                  :disabled="detailType === 'check'||detailType === 'approve'||detailType==='deal'||detailType==='stamp'"
                  v-on:change="getProjectByCompanyId()"
                  value-key="id"
                  placeholder="选择公司"
                  clearable
                >
                  <el-option
                    v-for="item in companyTree"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="项目" prop="projectId" :label-width="formlabelWidth">
                <el-select
                  style="margin: 0; margin-right: 15px;width: 100%"
                  class="select"
                  size="small"
                  v-model="formBaseData.projectId"
                  :disabled="detailType === 'check'||detailType === 'approve'||detailType==='deal'||detailType==='stamp'"
                  v-on:change="getSectionByProjectId()"
                  value-key="id"
                  filterable
                  placeholder="选择项目"
                  clearable
                >
                  <el-option
                    v-for="item in projectTree"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="标段" prop="sectionId" :label-width="formlabelWidth">
                <el-select
                  style="margin: 0; margin-right: 15px;width: 100%"
                  class="select"
                  size="small"
                  @change="changeSectionInfo"
                  v-model="formBaseData.sectionId"
                  :disabled="detailType === 'check'||detailType === 'approve'||detailType==='deal'||detailType==='stamp'"
                  placeholder="选择标段"
                  clearable
                >
                  <el-option
                    v-for="item in sectionTree"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item class="" label="天气情况" required :label-width="formlabelWidth">
                <el-radio-group v-model="formBaseData.weatherChoose" size="medium" class="weatherRadio"
                                :disabled="detailType === 'check'|| detailType === 'approve' "
                                @change="updateData">
                  <el-radio-button label="晴" ></el-radio-button>
                  <el-radio-button label="阴"></el-radio-button>
                  <el-radio-button label="雨"></el-radio-button>
                  <el-radio-button label="雪"></el-radio-button>
                  <el-radio-button label="其他"></el-radio-button>
                </el-radio-group>

              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item  class="" label="手动输入天气情况" required :label-width="formlabelWidth"
                             v-show="formBaseData.weatherChoose == '其他'">
                <el-input
                  class="input"
                  size="small"
                  v-model="formBaseData.weatherText"
                  placeholder="请输入天气情况"
                  :disabled="detailType === 'check'|| detailType === 'approve' "
                  clearable
                  @input="updateData"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item class="" label="施工单位" prop="constrCompanyName" :label-width="formlabelWidth">
                <el-input size="small" v-model="formBaseData.constrCompanyName"  placeholder=""
                          :disabled="true"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item class="" label="监理单位" prop="supervisorCompanyName" :label-width="formlabelWidth">
                <el-input size="small" v-model="formBaseData.supervisorCompanyName"  placeholder=""
                          :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item class="" label="编号" prop="logNumber" :label-width="formlabelWidth">
                <el-input size="small" v-model="formBaseData.logNumber"  placeholder=""
                          :disabled="detailType === 'check'|| detailType === 'approve' "></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item class="whole-line" label="巡查员" prop="constrUser" :label-width="formlabelWidth">
                <el-input size="small" v-model="formBaseData.constrUser"  placeholder=""
                          :disabled="detailType === 'check'|| detailType === 'approve' "></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item class="" label="巡视日期" prop="logDate"
                            :label-width="formlabelWidth">
                <el-date-picker
                  v-model="formBaseData.logDate"
                  type="date"
                  style="width:100%"
                  format='yyyy-MM-dd'
                  :picker-options="pickerOptions0"
                  value-format='yyyy-MM-dd'
                  placeholder="选择日期"
                  :disabled="detailType === 'check' || detailType === 'approve'">
                </el-date-picker>
              </el-form-item>

            </el-col>
            <el-col :span="12">
              <el-form-item  prop="isDay" >
                <el-radio-group v-model="formBaseData.isDay" :disabled="detailType === 'check'|| detailType === 'approve'" size="medium" style="padding-left: 10px">
                  <el-radio  :label="1">全天</el-radio>
                  <el-radio  :label="2">上午</el-radio>
                  <el-radio  :label="3">下午</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item class="whole-line" label="安全隐患处理意见书编号" prop="opinionNo" :label-width="formlabelWidth">
                <el-input size="small" v-model="formBaseData.opinionNo"  placeholder="发出安全隐患处理意见书编号"
                          :disabled="detailType === 'check'|| detailType === 'approve' "></el-input>
              </el-form-item>
            </el-col>

          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item prop="constrRemark" label="主要问题及整改意见" :label-width="formlabelWidth">
                <el-input
                  class="fill"
                  type="textarea"
                  :autosize="{ minRows: 4, maxRows: 6}"
                  placeholder="主要问题及整改意见"
                  v-model="formBaseData.constrRemark"
                  :disabled="detailType === 'check'|| detailType === 'approve' "
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <div class="info-detail-box">
              <div class="left-box">
                <div class="left-content-box WholeScroll">
                  <div class="flex-row-bridge" v-for="(item,index) in leftEquip" :key="index">
                    <p :class="chooseIndex == index?'chooseText':''"  @click="chooseIndex = index">{{item.leftName}}</p>
                    <i class="iconfont icon-shanchu2" @click="deleteLeftEquip(index)"  v-if="detailType!='check' && detailType != 'approve'"></i>
                  </div>
                </div>
                <div class="left-bottom-group">
                  <el-button
                    type="primary" size="small"
                    class="add buildButtonStyle"
                    v-if="detailType!='check' && detailType != 'approve'"
                    @click="addEquip()"> 新增记录
                  </el-button>
                </div>
              </div>
              <div  v-if="chooseIndex>=0&&leftEquip.length>0" class="right-box WholeScroll">
                <div>
                  <el-col :span="24">
                    <el-form-item
                      required
                      label="施工点(工程地点)"
                      :label-width="formlabelWidth"
                    >
                      <el-input   class="fill" style="width: 100%;" type="textarea"   placeholder="请输入施工点(工程地点)" :autosize="{ minRows: 2, maxRows: 4 }"
                                  v-model="leftEquip[chooseIndex].deviceCode" @change="changeLeftName(leftEquip[chooseIndex])" :disabled="detailType === 'check' || detailType === 'approve'">
                      </el-input>

                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item
                      label="隐患或危险因素描述"
                      :label-width="formlabelWidth"
                    >
                      <el-input
                        class="fill"
                        style="width: 100%;"
                        type="textarea"
                        :autosize="{ minRows: 4, maxRows: 4 }"
                        placeholder="请输入隐患或危险因素描述"
                        v-model="leftEquip[chooseIndex].hiddenDangerFactors"
                        :disabled=" detailType === 'check' || detailType === 'approve' "
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>

                  <el-col :span="24">
                    <el-form-item
                      label="处理意见及措施"
                      :label-width="formlabelWidth"
                    >
                      <el-input
                        class="fill"
                        style="width: 100%;"
                        type="textarea"
                        :autosize="{ minRows: 4, maxRows: 4 }"
                        placeholder="请输入处理意见及措施"
                        v-model="leftEquip[chooseIndex].handlingOpinions"
                        :disabled=" detailType === 'check' || detailType === 'approve' "
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>



                  <el-col :span="24">
                    <el-form-item
                      label="备注"
                      :label-width="formlabelWidth"
                    >
                      <el-input
                        class="fill"
                        style="width: 100%;"
                        type="textarea"
                        :autosize="{ minRows: 4, maxRows: 4 }"
                        placeholder="请输入简介"
                        v-model="leftEquip[chooseIndex].remarks"
                        :disabled=" detailType === 'check' || detailType === 'approve' "
                      >
                      </el-input>
                    </el-form-item>
                  </el-col>

                </div>
              </div>
              <div class="flex-hv-center"  v-if="leftEquip.length == 0">暂无数据</div>
            </div>
          </el-row>
          <el-row>

            <el-col  :span="19"  style="position: relative" class="otherMeterageUpload">
              <el-form-item label="附件" :label-width="formlabelWidth">
                <cmsUploadFile
                  ref="fileOne"
                  :detail-id="detailId"
                  :fileSystem="fileSystem['one']"
                  :disabled="detailType === 'check'|| detailType === 'approve'"
                  type="mul"
                  :fileList="fileList"
                  info="支持上传 png/jpg/gif/doc/xlsx/ppt/pdf等文件"
                  :detail-type="detailType" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <!--api操作按钮 除去上报-->
        <!--新建和编辑的暂存上报-->
        <template v-if="detailType === 'build' || detailType === 'edit'">
          <!--   <el-button size="small" type="primary" :loaidng="isLoading" @click="handleClickDeal('submit', {flag: 1})"><i class="iconfont icon-icon_save"></i> 确 定</el-button>-->
          <el-button size="small" type="primary" :loading="isLoading" @click="handleClickDeal('createFile', {flag: 1})">
            <i class="iconfont icon-icon_save"></i> 确 定</el-button>
        </template>
        <el-button size="small" @click="handleClickDeal('cancel')"><i class="iconfont icon-icon_cancel"></i> 取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import projectSectionInfo from "@/api/buss/common";
  import sectionInfo from "@/api/buss/sectionInfo";
  import msgUtil from "@/utils/msgUtil";
  import sgxslog from "@/api/buss/sgxslog";
  import store from "@/store";
  import { getCompanyBySecId } from '../../../../api/buss/sectionInfo'
  import file from "@/api/file";
  import { Base64 } from 'js-base64'
  export default {
    name: "sgxslog-manage-detail",
    props: {
      postDetail: {
        type: Object,
        default: {
          show: false,
          type: 'build',
          params: {}
        }
      }
    },
    watch: {
      postDetail(value) {
        console.log(value.type)
        // 显示详情弹窗
        this.formShow = value.show
        // 初始化窗口参数
        this.activeName = 'first'
        // 详情类型
        this.detailType = value.type
        if (this.detailType == 'build') {
          this.title = '新增施工安全巡视记录'
          this.formBaseData.constrUser = store.getters.user.name
          this.isShowBpmn=true
        } else if (this.detailType == 'check') {
          this.title = '查看施工安全巡视记录'
        } else if (this.detailType == 'edit') {
          this.isShowBpmn=true
          this.title = '编辑施工安全巡视记录'
        }else if (this.detailType == 'approve') {
          this.isShowBpmn=true
          this.title = '施工安全巡视记录审核'
        }else {
          this.title = ''
        }

        // 详情id
        this.detailId = value.detailId?value.detailId:'';
        // 非新建详情时 获取详情
        if (this.detailType == 'build') {
          this.$nextTick(()=>{
            this.$refs['formBaseData'].resetFields()
            this.initData()

          })
        } else {
          // 获取详情请求
          this.initData().then(res=>{
            this.getDetail()
          })
        }
      }
    },
    data() {
      return {
        pickerOptions0: {
          disabledDate(time) {
            return time.getTime() > Date.now() - 8.64e6
          }
        },
        leftEquip:[],
        chooseIndex:0,
        fileList: [],
        isCreateFile:'',
        companyTree: [], // 公司下拉
        projectTree: [], // 项目下拉
        sectionTree: [], // 标段下拉
        checkInitShow:false,
        isLoading:false,
        actionType: '查看',
        title: '施工安全巡查记录',
        isYz:false,//上报人公司类型 是否是业主
        //存放图片的数组
        fileListArray: [],
        detailType: 'build', // 详情类型 build新建 check不可编辑查看 edit编辑
        detailId: '', // 当前详情的id
        activeName: 'first', //
        detailActions: [], // 当前详情的操作项
        formShow: false, // 表单展示
        radioValue:'',//单选按钮选中的值
        formlabelWidth: '180px', // 表单左侧标题宽度
        selectList: {
          file: [], // 文件
          approver: [], // 审批人
          structureType: [], // 结构类型
        },
        fileSystem: {
          'one': {
            sys: 'buss',
            module: 'sgxslog',
            part: 'one',
            compoName: 'fileOne'
          }
        }, // 文件系统的参数
        // 所有下拉框列表的集合
        // 表单基本信息内容
        formBaseData: {
          companyId:'',
          sectionId:'',
          type:'1',
          isDay:1,
          projectId:'',
          constrCompany:'',//施工单位
          constrCompanyName:'',//施工单位
          supervisorCompany:'',//监理单位
          supervisorCompanyName:'',//监理单位
          logNumber:'',//日志编号
          logDate:new Date().Format("yyyy-MM-dd"),//施工日志日期
          constrUser:'',//记录人
          constrRemark:'',//备注
          mes:'',
          opinionNo:'',
          weather:'晴',
          weatherChoose:'晴',
          weatherText:'晴',
          log: [], // 日志
        },
        weatherList:[{label:'晴',value:'晴'},{label:'阴',value:'阴'},{label:'雨',value:'雨'},{label:'雪',value:'雪'}],
        // 表单基本信息验证
        formBaseRules: {
          companyId: [
            {required: true, message: '请选择' + '公司', trigger: 'change'},
          ],
          projectId: [
            {required: true, message: '请选择' + '项目', trigger: 'change'},
          ],
          sectionId: [
            {required: true, message: '请选择' + '标段', trigger: 'change'},
          ],
          logNumber: [
            {required: true, message: '请输入' + '编号', trigger: 'change'},
          ],
          logDate: [
            {required: true, message:'请输入'+'巡视日期' , trigger: 'blur'},
          ],
          constrUser: [
            {required: true, message:'请输入'+'巡查员' , trigger: 'blur'},
          ],
          opinionNo: [
            {required: true, message:'请选择'+'发出安全隐患处理意见书编号' , trigger: 'blur'},
          ],
          weather: [
            {required: true, message:'请选择'+'天气' , trigger: 'blur'},
          ],
          constrRemark: [
            {required: true, message:'请选择'+'主要问题及整改意见' , trigger: 'blur'},
          ],

        },

      }
    },
    created () {
    },
    methods: {
      openFile () {
        sgxslog.getOne(this.detailId).then(res => {
          if (res.code == 200) {
            let fileId = res.data.fileId
            this.viewFile(fileId)
          }else {
            msgUtil.error2(res.data.message)
          }
        }).catch(() => {
          msgUtil.error2("打开文件失败")
        })
      },
      addEquip(){
        let arr = {
          leftName:'施工点(工程地点)',
          deviceCode:'',
          hiddenDangerFactors:'',
          handlingOpinions: '',
          remarks:'',

        }
        this.leftEquip.push(arr)
      },
      viewFile(e) {
        this.loading = true
        file.preview(e).then(response => {
          //  如果是minio地址路径，则调用kkview
          if(!response.data.startsWith("/")) {
            window.open(PREVIEW_URL + '/onlinePreview?url=' + encodeURIComponent(Base64.encode(response.data)));
          }else{
            //  如果是转换后的previewGetFile，浏览器直接打开
            window.open(response.data);
          }
          this.loading = false
        })
      },
      changeSectionInfo(){
        sectionInfo.getCompanyBySecId(this.formBaseData.sectionId).then(res => {
          if (res.status === 1) {
            var data = res.data;
            this.formBaseData.constrCompanyName=data.buildUnit
            this.formBaseData.supervisorCompanyName=data.supervisorUnit
            this.formBaseData.constrCompany=data.buildUnitId
            this.formBaseData.supervisorCompany=data.supervisorUnitId && data.supervisorUnitId.length>0  ? data.supervisorUnitId[0] : ""
          }else {
            msgUtil.error2(res.data.message)
          }
        }).catch(() => {
          msgUtil.error2("获取标段相关单位失败")
        })
      },
      initData(){
        this.companyTree = []

        return   projectSectionInfo.getProjectSectionInfoTree().then(res => {
          if (res.code === 200) {
            var data = res.data;
            this.companyTree = data
            if(this.detailType=='build' && this.companyTree.length>0){
              this.formBaseData.companyId = this.companyTree[0].id;
              this.getProjectByCompanyId()
            }
            return new Promise(resolve => {
              resolve(res)
            })
          }else {
            msgUtil.error2(res.data.message)
          }
        }).catch(() => {
          msgUtil.error2("获取项目标段树失败")
        })

      },

      getLogNumber(){
        let sectionId = this.formBaseData.sectionId
        this.$httpGet('buss/commonAPI/getLogNumber?type=3&sectionId='+sectionId).then(res => {
          if (res.code === 200) {
            this.formBaseData.logNumber = res.data
          }else {
            msgUtil.error2(res.data.message)
          }
        }).catch((res) => {
        })
      },

      /**
       *  根据建设单位查询下面的所有项目
       * */
      getProjectByCompanyId() {
        if(this.formBaseData.projectId&&!this.checkInitShow){
          this.formBaseData.projectId = ''
        }
        if(this.formBaseData.sectionId&&!this.checkInitShow){
          this.formBaseData.sectionId = ''
        }

        this.companyTree.forEach((item) => {
          if (item.id === this.formBaseData.companyId) {
            this.projectTree = item.children
            if(this.detailType =='build' && this.projectTree.length>0){
              this.formBaseData.projectId = this.projectTree[0].id;
              this.getSectionByProjectId();
            }
          }
        })
      },
      changeLeftName(item){
        item.leftName = item.deviceCode
      },
      /**
       * 根据项目id获取标段列表
       * getContractByProjectId
       * */
      getSectionByProjectId() {

        if(this.formBaseData.sectionId&&!this.checkInitShow){
          this.formBaseData.sectionId = ''
        }

        if(this.checkInitShow){
          this.checkInitShow=false
        }

        if (this.formBaseData.projectId) {
          this.projectTree.forEach((item) => {
            if (item.id == this.formBaseData.projectId) {
              this.sectionTree = item.children
              if(this.detailType =='build' && this.sectionTree.length>0){
                this.formBaseData.sectionId = this.sectionTree[0].id;
                this.getLogNumber();
                this.changeSectionInfo();
              }
            }
          })
        }
      },

      // 获取详情请求 api
      getDetail () {
        sgxslog.getOne(this.detailId).then(res => {
          if (res.code == 200) {
            this.formBaseData=res.data
            if(this.formBaseData.weather != '晴'&&this.formBaseData.weather != '阴'&&this.formBaseData.weather != '雨'&&this.formBaseData.weather != '雪'){
              this.formBaseData.weatherChoose = '其他'
              this.formBaseData.weatherText = this.formBaseData.weather
            }else {
              this.formBaseData.weatherChoose = this.formBaseData.weather
            }

            if(this.formBaseData.mes){
              this.leftEquip = JSON.parse(this.formBaseData.mes)
            }
            this.checkInitShow=true
            this.getProjectByCompanyId()
            this.getSectionByProjectId()
            this.changeSectionInfo()
            this.loadFiles()
          }else {
            msgUtil.error2(res.data.message)
          }
        }).catch(() => {
          msgUtil.error2("获取详情信息失败")
        })
      },

      // 提交详情 提交1/暂存0 新建0/修改1
      submitDetail (type, callback,slient) {
        this.formBaseData.isCreateFile = '0'
        if (this.detailType === 'build') {
          this.isLoading=true
          let leftarr  = JSON.parse(JSON.stringify(this.leftEquip))
          this.formBaseData.mes= JSON.stringify(leftarr)
          sgxslog.submit(this.formBaseData).then(res => {
            if (res.code === 200) {
              this.formShow = false
              this.detailId = res.data.id
              if (callback) callback()
            }else {
              msgUtil.error2(res.data.message)
            }
          }).catch((res) => {
            console.log(res)
            // this.$notify({
            //   title: '施工安全巡查记录保存失败',
            //   type: 'error',
            //   duration: 2500
            // })
          }).finally((response) => {
            this.isLoading = false
          })
        }else{
          this.isLoading=true
          sgxslog.resubmit(this.formBaseData).then(res => {
            if (res.code === 200) {
              this.formShow = false
              this.detailId = res.data.id
              if (callback) callback()
            }else {
              msgUtil.error2(res.data.message)
            }
          }).catch((res) => {
            console.log(res)
            // this.$notify({
            //   title: '施工安全巡查记录保存失败',
            //   type: 'error',
            //   duration: 2500
            // })
          }).finally((response) => {
            this.isLoading = false
          })
        }
      },
      // 事件处理的api请求
      sealDealHttp (url, query, params, callback) {
        this.$httpPost(
          this.$store.state.httpHost.buss + url + query,
          params
        ).then(res => {
          if (res.data.status === 1) {
            if (callback) callback(res.data)
          } else {
            this.$messageError(res.data.message)
          }
        }).catch(res => {
          console.log(res)
        })
      },
      // 点击各个流程的按钮事件
      handleClickDeal (type, res) {
        console.log(type, res)
        switch (type) {
          // 取消，关闭窗口
          case 'cancel':
            // 重置表单验证
            this.$refs['formBaseData'].resetFields()
            // 清空表单内容
            this.formBaseData = {
              isCreateFile:'',
              companyId:'',
              sectionId:'',
              projectId:'',
              isDay:1,
              constrCompany:'',//施工单位
              constrCompanyName:'',//施工单位
              supervisorCompany:'',//监理单位
              supervisorCompanyName:'',//监理单位
              logNumber:'',//日志编号
              logDate:'',//施工日志日期
              constrUser:'',//专职安全员
              constrRemark:'',//备注
              log: [], // 日志
              mes:'',
              opinionNo:'',
              weather:'晴',
              weatherChoose:'晴',
              weatherText:'晴',

            } // 表单基本信息内容
            // 清空文件
            this.fileList = []
            this.leftEquip=[]
            for (let k in this.fileSystem) {
              let fileProp = this.fileSystem[k]
              this.$refs[fileProp.compoName].cancelAll()
            }
            // 关闭弹窗
            this.formShow = false
            break
          // 保存
          case 'submit':
            let flag = res.flag
            // 表单验证
            this.$refs['formBaseData'].validate((valid) => {
              if (valid) {
                if(this.formBaseData.weatherChoose == '其他'){
                  this.formBaseData.weather = this.formBaseData.weatherText
                }else {
                  this.formBaseData.weather = this.formBaseData.weatherChoose
                }
                // 提交详情
                this.submitDetail(flag, () => {
                  this.saveFiles()
                  setTimeout(() => {
                    this.$emit('reloadList')
                    this.$notify({
                      title: '施工安全巡视记录保存成功',
                      type: 'success',
                      duration: 1500
                    })
                  }, 1500)

                },true)
              }
            });
          case 'createFile':
            // 表单验证
            this.$refs['formBaseData'].validate((valid) => {
              if (valid) {
                if(this.formBaseData.weatherChoose == '其他'){
                  if(this.formBaseData.weatherText){
                    this.formBaseData.weather = this.formBaseData.weatherText
                  }else{
                    msgUtil.error2("请输入天气情况");
                    return false;
                  }
                }else {
                  this.formBaseData.weather = this.formBaseData.weatherChoose
                }
                // 提交详情
                this.submitAndCreateDetail(flag, () => {
                  this.saveFiles()
                  setTimeout(() => {
                    this.$emit('reloadList')
                    this.$notify({
                      title: '施工巡视日志保存成功',
                      type: 'success',
                      duration: 1500
                    })
                  }, 1500)
                },true)
              }
            });
            break
          // 删除
          case 'delete':

            break
        }
      },

      // 提交详情 提交1/暂存0 新建0/修改1
      submitAndCreateDetail (type, callback) {
        this.formBaseData.isCreateFile = '1'
        if (this.detailType === 'build') {
          alert
          let leftarr  = JSON.parse(JSON.stringify(this.leftEquip))
          this.formBaseData.mes= JSON.stringify(leftarr)
          if(this.formBaseData.mes==''||this.leftEquip.length==0){
            msgUtil.error2("请增加施工记录");
            return false;
          }
          this.isLoading=true
          sgxslog.submit(this.formBaseData).then(res => {
            if (res.code === 200) {
              this.formShow = false
              this.detailId = res.data.id
              // this.openFile()
              if (callback) callback()
            }else {

              msgUtil.error2(res.data.message)
            }
          }).catch((res) => {
            console.log(res)
            // this.$notify({
            //   title: '施工安全日志保存失败',
            //   type: 'error',
            //   duration: 2500
            // })
          }).finally((response) => {
            this.isLoading = false
          })
        }else{
          let leftarr  = JSON.parse(JSON.stringify(this.leftEquip))
          this.formBaseData.mes= JSON.stringify(leftarr)
          this.isLoading=true
          sgxslog.resubmit(this.formBaseData).then(res => {
            if (res.code === 200) {
              this.formShow = false
              this.detailId = res.data.id
              // this.openFile()
              if (callback) callback()
            }else {
              msgUtil.error2(res.data.message)
            }
          }).catch((res) => {
            console.log(res)
            // this.$notify({
            //   title: '施工安全日志保存失败',
            //   type: 'error',
            //   duration: 2500
            // })
          }).finally((response) => {
            this.isLoading = false
          })
        }
      },
      saveFiles() {
        for (let k in this.fileSystem) {
          let fileProp = this.fileSystem[k]
          this.$refs[fileProp.compoName].saveAll(this.detailId)
        }
      },

      updateData(){
        this.$forceUpdate()
      },
      deleteLeftEquip(index){
        this.$confirm('确定是否删除？', '提示', {
          confirmButtonClass: 'iconfont icon-icon_ok',
          cancelButtonClass: 'iconfont icon-icon_cancel',
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'info'
        })
          .then(() => {
            if(this.leftEquip.length == 1){
              this.$set(this,'leftEquip',[])
            }else {
              this.leftEquip.splice(index,1)
              let arr = JSON.parse(JSON.stringify(this.leftEquip))
              this.$set(this,'leftEquip',arr)
              this.chooseIndex = 0
            }

          })
          .catch(() => {
          })
      },
      loadFiles() {
        this.$nextTick(()=>{
          for (let k in this.fileSystem) {
            let fileProp = this.fileSystem[k]
            this.$refs[fileProp.compoName].init()
          }
        })
      },
    },
  }
</script>

<style scoped lang="scss">
  $borderColor: #C0C4CC;
  .device-manage-detail {
    .el-select.half {
      width: 250px;
    }

    .el-select.fill {
      width: 800px;
    }

    .contract-ele {
      //   width: 280px;
      width: 100%;
    }

    .el-input .el-select {
      width: 130px;
    }

    .fee_add {
      color: #008fe0;
      border-color: #008fe0;
      float: right;
      margin-bottom: 10px;
    }

    .dialog-section-title {
      font-size: 16px;
      font-weight: bold;
    }

    .dialog-upload-type {
      font-size: 14px;
      color: #008fe0;
      margin-left: 50px;
    }

    .contractNum {
      position: absolute;
      top: 0;
      right: 20px;

      p {
        color: #a71c1c;
      }
    }

    .icon-add {
      position: absolute;
      top: 0;
      right: 0;
      color: #008fe0;
      font-size: 30px;
      cursor: pointer;
    }

    .icon-subtract {
      position: absolute;
      top: 0;
      right: 0;
      color: #008fe0;
      font-size: 30px;
      cursor: pointer;
    }

    .form-tip {
      font-size: 12px;
      color: #a71c1c;
    }

    .scoreTXT {
      color: #008fe0;
      cursor: pointer;
    }

    .formTitle {
      font-weight: bold;
      font-size: 16px;
      margin: 15px 0;
    }

    .hoverTxt {
      color: #008fe0;
      cursor: pointer;
    }

    .upload-demo-fujian {
      width: 250px;
    }

    .upload-demo-zongtu {
      width: 300px;
    }

    .newArea {
      display: flex;
    }

    .pdf {
      display: flex;
      align-items: center;
      justify-content: left;
      cursor: pointer;
      flex-wrap: wrap;

      img {
        display: block;
        height: 20px;
        margin-right: 15px;
      }
    }

    .pdfItem {
      display: flex;
      position: relative;
      justify-content: space-between;
      padding-bottom: 5px;
      align-items: center;

      width: 100%;
      height: 40px;

      .pdfBox {
        padding-top: 5px;
        display: flex;
        justify-content: space-between;
        width: 100%;
        align-items: center;

        .content {
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          display: flex;
          align-items: center;
          flex: 1;
        }
      }

      .buttonG {
        display: flex;
      }
    }

    .btnGroup {
      display: flex;
      align-items: center;
      justify-content: left;
      flex-wrap: wrap;
      padding-top: 5px;

      button {
        margin-left: 10px !important;
        margin-bottom: 5px !important;
      }

    }

    .flexTitle {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }

    .g-flex-center {
      display: flex;
      align-items: center;
    }
  }
  .flex-row-bridge{
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    p{
      margin: 5px 0 ;
      max-width: 150px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    i{
      cursor: pointer;
    }
    i:hover{
      color: #a71c1c;
    }
  }
  .info-detail-box{
    border: 1px $borderColor solid;
    display: flex;
    flex-direction: row;
    margin: 30px 0;
    .left-box{
      min-width: 200px;
      padding: 0 0 15px 0;
      padding-bottom: 50px;
      border-right: 1px $borderColor solid ;
      position: relative;
      .left-content-box{
        padding: 15px;
        max-height: 350px;
        overflow-y: auto;
      }
      p{
        cursor: pointer;
      }
    }
    .right-box{
      flex-grow: 1;
      padding: 15px;
      padding-bottom: 30px;
    }
    .chooseText{
      color: #008fe0;
    }
  }
  .left-bottom-group{
    width: 100%;
    display: flex;
    align-items: center;
    flex-direction: row;
    justify-content: space-around;
    position: absolute;
    bottom: 10px;
    left: 0;
    .el-button{
    }
    .deleteBatch{
      background-color: rgba(215,215,215,0);
      border-color: #409EFF;
      color: #409EFF;
    }
  }
  .flex-hv-center{
    min-height: 100px;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;

  }
  .fileText{
    cursor: pointer;
    margin: 0;
    padding-left: 10px;
    display: flex;
    align-items: center;
    img {
      height: 20px;
      margin-right: 15px;
    }
    span {
      width: 40%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      word-break: keep-all;
      margin-right: 15px;
    }
  }
  .fileText:hover{
    background-color: rgb(245,247,250);
  }
</style>
